package jsyf.oa.service.system;

import com.alibaba.dubbo.common.utils.StringUtils;
import com.alibaba.fastjson.JSONObject;
import jsyf.oa.dao.system.Region2ProvinceDao;
import jsyf.oa.facade.system.Region2ProvinceFacade;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * Created by Lenovo on 2017/12/9.
 */
@Service
@Transactional(rollbackFor = Exception.class)
@com.alibaba.dubbo.config.annotation.Service(protocol = {"dubbo"})
public class Region2ProvinceService implements Region2ProvinceFacade {

    @Autowired
    private Region2ProvinceDao dao;
    @Override
    public boolean config(String regionId, String provinceIds) {
        dao.removeByCondition(" AND REGION_ID = ? ",new String[]{regionId});
        if(!StringUtils.isEmpty(provinceIds)){
           dao.insertBatch(regionId,provinceIds);
        }
        return true;
    }

    @Override
    public List<JSONObject> getByRegionId(String regionId) {
        return dao.getJSONListByCondition(" AND REGION_ID = ? ",new Object[]{regionId});
    }


}
